var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: "",
    designerList: [],
    ispaidan: false
  },
  delDesigner(designerId) {
    let t = this
    wx.request({
      url: app.globalData.Interfaceurl + 'delDesigner',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        token: t.data.token,
        designerId: designerId
      },
      success: res => {
        console.log(res)
        if (res.data.result == 0) {
          t.getDesignerList()
        } else {
          wx.showToast({
            title: res.data.message,
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          t.setData({
            token: app.token()
          })
        }
      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })


  },

  del(e) {
    let designerId = e.currentTarget.dataset.id
    let t = this
    wx.showModal({
      title: '提示',
      content: '是否确认删除该成员？',
      confirmColor: "#D6000F",
      success(res) {
        if (res.confirm) {
          t.delDesigner(designerId)
        } else if (res.cancel) {

        }
      }
    })
  },

  //跳转到添加设计师
  add() {
    wx.navigateTo({
      url: '/shopowner/pages/addpeople/addpeople?todo=adddesigner',
    })
  },
  // 显示按钮
  showBtn(e) {
    console.log(e)
    let index1 = e.currentTarget.dataset.index
    let designerList = this.data.designerList
    designerList.forEach((item, index2) => {
      item.isHidebtn = false
    });
    designerList[index1].isHidebtn = true

    this.setData({
      designerList: designerList
    })

  },
  determine() {
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2]; //prevPage 是获取上一个页面的js里面的pages的所有信息。 -2 是上一个页面，-3是上上个页面以此类推。\\
    prevPage.setData({
      finishFilesList: this.data.finishFilesList
    })
    wx.navigateBack({
      delta: 1,
    })
  },
  // 跳过
  skip(e) {
    let orderObj = this.data.orderObj
    orderObj.designer = {}
    orderObj.designerId = ""
    this.setData({
      orderObj: orderObj
    })
    wx.navigateTo({
      url: '/shopowner/pages/orderAttachment/orderAttachment?orderObj=' + JSON.stringify(orderObj)
    })
  },
  // 选择设计师
  choice(e) {
    // if (e.currentTarget.dataset.peopleobj.userId == '') {
    //   this.setData({
    //     ispaidan:true
    //   })
    //   return
    // }

    if (this.data.todo == 'modifyOrder') {

      let pages = getCurrentPages();
      let prevPage = pages[pages.length - 2]; //prevPage 是获取上一个页面的js里面的pages的所有信息。 -2 是上一个页面，-3是上上个页面以此类推。\\
      let orderObj = prevPage.data.orderObj
      orderObj.designerId = e.currentTarget.dataset.peopleobj.id
      orderObj.designerObj = e.currentTarget.dataset.peopleobj
      prevPage.setData({
        orderObj: orderObj
      })
      wx.navigateBack({
        delta: 1,
      })
    } else {




      let orderObj = this.data.orderObj
      console.log(e.currentTarget.dataset)
      orderObj.designerObj = e.currentTarget.dataset.peopleobj
      orderObj.designerId = e.currentTarget.dataset.peopleobj.id

      this.setData({
        orderObj: orderObj
      })




      wx.navigateTo({
        url: '/shopowner/pages/orderAttachment/orderAttachment?orderObj=' + JSON.stringify(orderObj)
      })
    }
  },



  // 隐藏授权
  hidepaidan() {
    this.setData({
      ispaidan: false
    })
  },








  binddistribute(e) {
    wx.navigateTo({
      url: '/shopowner/pages/addpeople/addpeople?todo=adddesigner&&designerid=' + e.currentTarget.dataset.designerid,
    })
  },


  bindSubmit() {
    wx.redirectTo({
      url: '/pages/unplone/unplone',
    })
  },
  // 搜索设计师
  bindconfirm() {
    this.getDesignerList()
  },
  // 输入时搜索
  fakeCallback() {
    let t = this
    clearTimeout(this.temporaryTimer)
    this.temporaryTimer = setTimeout(function () {
      t.getDesignerList()
    }, 500)
  },


  // 获得设计师列表
  getDesignerList() {
    let t = this
    wx.showLoading({
      title: '加载中',
      
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'getDesignerList',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        name: t.data.name,
      },
      success: res => {
        wx.hideLoading()
        let designerList = res.data.designerList
        designerList.forEach(item => {
          item.isHidebtn = false
        });
        t.setData({
          designerList: designerList
        })
      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      identity: app.globalData.identity,
      token: app.token(),
      orderObj: JSON.parse(options.orderObj)
    })
    if (options.todo) {
      this.setData({
        todo: options.todo,

      })
    }
    this.getDesignerList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})